package com.magima.core.repository;

import java.util.List;
import java.util.concurrent.locks.Lock;

import android.content.SharedPreferences.OnSharedPreferenceChangeListener;

public class Repository {
	protected StringProcessor mProcessor;
	protected Lock mLock = null;
	protected String mName = null;
	private String mType = null;
	
	public Repository(StringProcessor processor) {
		if ( processor == null )
			mProcessor = new StringProcessor();
		else
			mProcessor = processor;
	}
	public Repository() {
		mProcessor = new StringProcessor();
	}
	
	public Lock getLock(){
		return mLock;
	}

	public String getName(){
		return mName;
	}
	
	public String getType(){
		return mType;
	}
	
	public Repository checkVersion(String type){
		mType = type;
		RepositoryManager manager = RepositoryManager.getInstance();
		int targetVersion = manager.getRepositoryTargetVersion(this);
		if ( targetVersion > manager.getRepositoryVersion(this) ){
			if ( mLock != null )
				mLock.lock();
			try {
				this.remove();
				manager.setRepositoryVersion(this, targetVersion);
			} finally {
				if ( mLock != null )
					mLock.unlock();
			}
		}
		return this;
	}
	
	public void saveString(String data) {
		throw new UnsupportedOperationException();
	}
	
	public void saveString(String key, String data) {
		throw new UnsupportedOperationException();
	}
	
	public void saveString(int key, String data) {
		saveString(String.valueOf(key), data);
	}
	
	public void saveStrings(String[] keys, String[] datas) {
		throw new UnsupportedOperationException();
	}

	public String loadString() {
		throw new UnsupportedOperationException();
	}
	
	public List<String> loadAllString() {
		throw new UnsupportedOperationException();
	}
	
	public String loadString(String key) {
		throw new UnsupportedOperationException();
	}
	
	public String loadString(int key) {
		return loadString(String.valueOf(key));
	}
	
	public void remove(){
		throw new UnsupportedOperationException();
	}
	
	public void remove(String key){
		throw new UnsupportedOperationException();
	}
	
	public void remove(int key){
		remove(String.valueOf(key));
	}
	
	public void registerOnSharedPreferenceChangeListener(OnSharedPreferenceChangeListener listener) {
		throw new UnsupportedOperationException();
	}
}
